﻿#region Namespace References

using System;
using System.Windows.Forms;
using DynConDevCorp.OpenArch.SmartData.BillingDemo1.ApplicationBusinessObjects;
using DynConDevCorp.OpenArch.SmartData.Core;
using DynConDevCorp.OpenArch.SmartData.Interfaces.Attributes;
using DynConDevCorp.OpenArch.SmartData.WinForms;

#endregion

namespace DynConDevCorp.OpenArch.SmartData.BillingDemo1.SmartUIControls
{
    public partial class CustomerSummaryControl : SmartEntityControl
    {
        #region Constructors

        public CustomerSummaryControl()
        {
            InitializeComponent();
            bmcEntity.BoundEntityChanged += bmcEntity_BoundEntityChanged;  
            Customer = new SmartEntityLink<Customer>();
            Customer.LinkedEntityChanged += Customer_LinkedEntityChanged;
        }

        #endregion

        #region Public Instance Properties

        [AutoField]
        public SmartEntityLink<Customer> Customer { get; set; }

        #endregion

        #region Public Instance Methods

        private void bmcEntity_BoundEntityChanged(object sender, EventArgs e)
        {
            Customer boundCustomer = (Customer) bmcEntity.BoundEntity;
            Customer.LinkedEntity = boundCustomer;
        }

        private void Customer_LinkedEntityChanged(object sender, EventArgs e)
        {
            bmcCustomers.BoundEntity = Customer.LinkedEntity;
        }

        #endregion
    }
}